package com.ruoyi.web.controller.jiaxiao;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.JxRetakeSchedule;
import com.ruoyi.system.service.IJxRetakeScheduleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 补考安排Controller
 * 
 * @author ruoyi
 * @date 2025-01-27
 */
@RestController
@RequestMapping("/jiaxiao/retake")
public class JxRetakeScheduleController extends BaseController
{
    @Autowired
    private IJxRetakeScheduleService jxRetakeScheduleService;

    /**
     * 查询补考安排列表
     */
    @PreAuthorize("@ss.hasPermi('jiaxiao:retake:list')")
    @GetMapping("/list")
    public TableDataInfo list(JxRetakeSchedule jxRetakeSchedule)
    {
        startPage();
        List<JxRetakeSchedule> list = jxRetakeScheduleService.selectJxRetakeScheduleList(jxRetakeSchedule);
        return getDataTable(list);
    }

    /**
     * 导出补考安排列表
     */
    @PreAuthorize("@ss.hasPermi('jiaxiao:retake:export')")
    @Log(title = "补考安排", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, JxRetakeSchedule jxRetakeSchedule)
    {
        List<JxRetakeSchedule> list = jxRetakeScheduleService.selectJxRetakeScheduleList(jxRetakeSchedule);
        ExcelUtil<JxRetakeSchedule> util = new ExcelUtil<JxRetakeSchedule>(JxRetakeSchedule.class);
        util.exportExcel(response, list, "补考安排数据");
    }

    /**
     * 获取补考安排详细信息
     */
    @PreAuthorize("@ss.hasPermi('jiaxiao:retake:query')")
    @GetMapping(value = "/{retakeId}")
    public AjaxResult getInfo(@PathVariable("retakeId") Long retakeId)
    {
        return success(jxRetakeScheduleService.selectJxRetakeScheduleByRetakeId(retakeId));
    }

    /**
     * 新增补考安排
     */
    @PreAuthorize("@ss.hasPermi('jiaxiao:retake:add')")
    @Log(title = "补考安排", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JxRetakeSchedule jxRetakeSchedule)
    {
        return toAjax(jxRetakeScheduleService.insertJxRetakeSchedule(jxRetakeSchedule));
    }

    /**
     * 修改补考安排
     */
    @PreAuthorize("@ss.hasPermi('jiaxiao:retake:edit')")
    @Log(title = "补考安排", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JxRetakeSchedule jxRetakeSchedule)
    {
        return toAjax(jxRetakeScheduleService.updateJxRetakeSchedule(jxRetakeSchedule));
    }

    /**
     * 删除补考安排
     */
    @PreAuthorize("@ss.hasPermi('jiaxiao:retake:remove')")
    @Log(title = "补考安排", businessType = BusinessType.DELETE)
	@DeleteMapping("/{retakeIds}")
    public AjaxResult remove(@PathVariable Long[] retakeIds)
    {
        return toAjax(jxRetakeScheduleService.deleteJxRetakeScheduleByRetakeIds(retakeIds));
    }

    /**
     * 查询学员的待考试补考安排
     */
    @PreAuthorize("@ss.hasPermi('jiaxiao:retake:query')")
    @GetMapping("/student/{studentId}/subject/{subjectId}")
    public AjaxResult getPendingRetakeByStudentAndSubject(@PathVariable("studentId") Long studentId, 
                                                         @PathVariable("subjectId") Long subjectId)
    {
        JxRetakeSchedule retakeSchedule = jxRetakeScheduleService.selectPendingRetakeByStudentAndSubject(studentId, subjectId);
        return success(retakeSchedule);
    }

    /**
     * 查询学员所有待考试的补考安排
     */
    @PreAuthorize("@ss.hasPermi('jiaxiao:retake:query')")
    @GetMapping("/student/{studentId}")
    public AjaxResult getPendingRetakesByStudent(@PathVariable("studentId") Long studentId)
    {
        List<JxRetakeSchedule> list = jxRetakeScheduleService.selectPendingRetakesByStudent(studentId);
        return success(list);
    }

    /**
     * 查询指定日期范围内的补考安排
     */
    @PreAuthorize("@ss.hasPermi('jiaxiao:retake:query')")
    @GetMapping("/calendar")
    public AjaxResult getRetakeScheduleByDateRange(@RequestParam("startDate") String startDate, 
                                                  @RequestParam("endDate") String endDate)
    {
        List<JxRetakeSchedule> list = jxRetakeScheduleService.selectRetakeScheduleByDateRange(startDate, endDate);
        return success(list);
    }

    /**
     * 完成补考安排
     */
    @PreAuthorize("@ss.hasPermi('jiaxiao:retake:edit')")
    @Log(title = "完成补考安排", businessType = BusinessType.UPDATE)
    @PutMapping("/complete/{retakeId}")
    public AjaxResult complete(@PathVariable("retakeId") Long retakeId)
    {
        return toAjax(jxRetakeScheduleService.completeRetakeSchedule(retakeId));
    }

    /**
     * 取消补考安排
     */
    @PreAuthorize("@ss.hasPermi('jiaxiao:retake:edit')")
    @Log(title = "取消补考安排", businessType = BusinessType.UPDATE)
    @PutMapping("/cancel/{retakeId}")
    public AjaxResult cancel(@PathVariable("retakeId") Long retakeId)
    {
        return toAjax(jxRetakeScheduleService.cancelRetakeSchedule(retakeId));
    }
}
